#include <scdl/parser/Symbol.hpp>

#include <cstdlib>
#include <cstring>
#include <iostream>

using std::cout;
using namespace scdl;

Product::Product()
        : left(0), right(0)
{
}

Product::~Product()
{
        if (left)
                left->unref();
        if (right)
                right->unref();
}

SymbolCategory Product::getCategory()
{
        return CATEGORY_PRODUCT;
}

void Product::prettyPrint(bool verbose)
{
        cout << "(";
        if (left) {
                left->prettyPrint();
                cout << " -> ";
        }
        if (right) {
                right->prettyPrint();
        }
        cout << ")";
        if (verbose && type) {
                cout << " : ";
                type->prettyPrint();
        }
}

void Product::setFactor(Symbol *left, Symbol *right)
{
        this->left = left;
        left->ref();
        this->right = right;
        right->ref();
        this->level = LEVEL_CLASS;
}

Symbol *Product::leftFactor()
{
        return left;
}

Symbol *Product::rightFactor()
{
        return right;
}
